<?php
/**
 * ==============================================
 * Copy right 2015-2016 http://wei.meididi88.com
 * ----------------------------------------------
 * This is not a free software, without any authorization is not allowed to use and spread.
 * ==============================================
 * @author: hy
 * @date: 2015-9-10
 * @version: v1.0.0
 */
namespace Admin\Behaviors;

use Think\Behavior;

/**
 * 用户注册成功后的行为扩展
 */
class OperationBehavior extends Behavior{
	
	public function run(&$params) {
		
		$ip = get_client_ip();
		$adminId = $_SESSION['ADMIN_ID'];
		
		$MenuModel = D('Menu');
		$operation = array(
			'app' => MODULE_NAME,
			'model' => CONTROLLER_NAME,
			'action' => ACTION_NAME
		);
		
		$menu = $MenuModel->where(array(
			'app' => MODULE_NAME,
			'model' => CONTROLLER_NAME,
			'action' => ACTION_NAME
		))->find();
		
		$operation = array_merge($operation, $params);
		$userId = $params ['admin_id'];
		
		$OperationModel = M('operation');
		$operation ['ip'] = $ip;
		
		if (!isset($params ['remark'])) {
			$remark = $menu ['name'];
			$operation ['remark'] = $menu ['name'];
		}
		
		$operation ['admin_id'] = $adminId;
		$operation ['created'] = time();
		$OperationModel->add($operation);
	}
}

?>